// date_range.cpp

#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <boost/date_time/gregorian/gregorian.hpp>

#include "from_yyyyddd_string.h"

using namespace std;
using namespace boost::gregorian;

int main(int argc, char *argv[])
{
	string str1, str2;

	if(argc < 2)
	{
		cout << "Usage: date_range {yyyyddd/yyyymmdd} {yyyyddd/yyyymmdd}" << endl;
		return 0;
	}
	else if(argc == 2)
	{
		str1 = argv[1];
		str2 = argv[1];
	}
	else if(argc >= 3)
	{
		str1 = argv[1];
		str2 = argv[2];
	}
	
	date d1, d2;
	bool as_julian = false;
	if(str1.length() == 7)
	{
		d1 = from_yyyyddd_string(str1); 
		as_julian = true;
	}
	else
	{
		d1 = from_undelimited_string(str1);
	}
	
	if(str2.length() ==7)
	{
		d2 = from_yyyyddd_string(str2);
	}
	else
	{
		d2 = from_undelimited_string(str2);
	}

	if(d1 > d2)
	{
		swap(d1, d2);
	}

	day_iterator iter(d1);

	while(iter <= d2)
	{
		if(as_julian)
		{
			cout << iter->year()
					<< setw(3) << setfill('0') << iter->day_of_year() << endl;
		}
		else
		{
			cout << iter->year()  
					<< setw(2) << setfill('0') <<  iter->month().as_number()
					<< setw(2) << setfill('0') << iter->day() << endl;
		}
		++iter;
	}
	
	return 0;
}
